package xyz.jiang.asteroid.pojo.entity;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.exc.IgnoredPropertyException;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import xyz.jiang.asteroid.common.base.BaseModel;
import xyz.jiang.asteroid.common.constants.UserStatus;

import java.util.Collection;
import java.util.List;

@Data
@TableName("user")
public class User extends BaseModel implements UserDetails{


    private String username;

    private String password;

    private String profile;

    private String nickname;

    private Integer gender;

    private String phone;

    private String email;

    private Integer status;

    @TableField(exist = false)
    private List<String> roles;

    @TableField(exist = false)
    private List<GrantedAuthority> authorities;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.status != UserStatus.ACCOUNT_EXPIRED;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.status != UserStatus.LOCKED;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.status != UserStatus.PASSWD_EXPIRED;
    }

    @Override
    public boolean isEnabled() {
        return status == UserStatus.NORMAL;
    }
}
